home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Menu / MenuControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-20  |  5.1 KB  |  215 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menucontrol.c
  5.  
  6.     DESCRIPTION
  7.     [X]DME intuition interface to menustrips.c
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.     none known
  13.  
  14.     TODO
  15.     handling for MENU_HELP
  16.  
  17.     EXAMPLES
  18.  
  19.     SEE ALSO
  20.     mainloop
  21.  
  22.     INDEX
  23.  
  24.     HISTORY
  25.     18 Dec 1992 b_null created
  26.     11 Feb 1993 modifcations
  27.     $Date: 1994/09/20 11:09:14 $ last update
  28.  
  29. ******************************************************************************/
  30.  
  31. /**************************************
  32.         Includes
  33. **************************************/
  34. #include "defs.h"
  35. #include "menubase.h"
  36.  
  37.  
  38. /**************************************
  39.         Globale Variable
  40. **************************************/
  41. Prototype APTR menu_cmd (struct IntuiMessage * im);
  42. /* Prototype void menu_cmd (struct IntuiMessage * im); */
  43. Prototype void *active_menu;
  44.  
  45.  
  46. /**************************************
  47.       Interne Defines & Strukturen
  48. **************************************/
  49.  
  50. typedef struct INode {
  51.     struct MinNode node;
  52.     XITEM     * item;
  53.     int        len;
  54.     char       com[0];  /* that means : the rest of that node contains a string */
  55. } IINODE;
  56.  
  57.  
  58. /**************************************
  59.         Interne Variable
  60. **************************************/
  61.  
  62. void *active_menu = NULL;
  63.  
  64. /**************************************
  65.        Interne Prototypes
  66. **************************************/
  67.  
  68.  
  69. #ifndef NOT_DEF
  70.  
  71. /*****************************************************************************
  72.  
  73.     NAME
  74.     menu_cmd
  75.  
  76.     PARAMETER
  77.     struct IntuiMessage * im
  78.  
  79.     RESULT
  80.     -/-
  81.  
  82.     RETURN
  83.     void
  84.  
  85.     DESCRIPTION
  86.     work on all menuselections done;
  87.     first set them all into a new queue, that does not
  88.     change if we modify currentmenu, then pass 'em to the
  89.     parser (or better a duplicate of them)
  90.  
  91.     NOTES
  92.     that method disables use of MENU_HELP
  93.     we should be able to do almost everything to our menus, also during
  94.     work on multiselections!
  95.  
  96.     THAT FUNCTION SHOULD BE RE-ENTRANT
  97.  
  98.     BUGS
  99.     what, if we close our window during that operation ????
  100.  
  101.     WARN: that function was neither compiled nor tested up to now
  102.           (we still use the function at the end of this file)
  103.  
  104.     EXAMPLES
  105.  
  106.     SEE ALSO
  107.     main/main
  108.  
  109.     INTERNALS
  110.     our method is horrible - it takes lots of resources,
  111.     but I think, this is the easiest way (else we had to lock our menustrip
  112.     and then queue up all operations to it)
  113.  
  114.     HISTORY
  115.     18 Dec 1992 b_null created
  116.     09 Feb 1993 b_null multiselection added
  117.     11 Feb 1993 b_null BUG FIX : all selections are done "buffered"
  118.  
  119. ******************************************************************************/
  120.  
  121. APTR /* void */ menu_cmd (struct IntuiMessage * im)
  122. {
  123.     MENUSTRIP * ms = currentmenu();
  124.     struct MinList buffs;
  125.  
  126.     NewList ((struct List *)&buffs);
  127.     if (im != NULL && im->Class == IDCMP_MENUPICK && ms != NULL) {
  128.     long           code = im->Code;
  129.     XITEM         * item;
  130.     IINODE         * in;
  131.  
  132.     while ((item = (XITEM *)ItemAddress (ms->data, code))) {
  133.         if (item->com != NULL) {
  134.         int len = sizeof (IINODE) + strlen (item->com) + 1;
  135.  
  136.         if ((in = AllocFunc (len, MEMF_ANY))) {
  137.             in->len = len;         /* we MUST remember the size here, as do_command might destroy the string-contents */
  138.             strcpy (in->com, item->com);
  139.             in->item = item;
  140.             AddTail ((struct List *)&buffs, (struct Node *)in);
  141.             /* if (item->Flags & CHECKED)
  142.             in->len = -in->len; */
  143.         } /* if malloced */
  144.         } /* if command carrier */
  145.         code = item->item.NextSelect;
  146.     } /* while pending selections */
  147.  
  148.  
  149.     while ((in = (IINODE *)RemHead ((struct List *)&buffs))) {
  150.         active_menu = in->item;
  151.         do_command (in->com);
  152.         FreeFunc (in, /* ABS */ (in->len));
  153.     } /* while commands left in queue */
  154.     active_menu = NULL;
  155.  
  156. #ifdef NOT_DEF
  157.     /* that method has one serious bug: we can not be sure to hit the right items */
  158.     char buffer[LINE_LENGTH];
  159.     while (item = (XITEM *)ItemAddress (ms->data, code)) {
  160.         if (item->com) {
  161.         strcpy (buffer, item->com);
  162.         do_command (buffer);
  163.         clearbreaks ();
  164.         } /* if item->com */
  165.     } /* while item */
  166. #endif
  167.     } /* if im */
  168.  
  169.     return (NULL);
  170. } /* menu_cmd */
  171.  
  172. #else
  173.  
  174. /*****************************************************************************
  175.  
  176.     RESULT
  177.     address of a command that is referred by the
  178.     selected menu;
  179.  
  180.     RETURN
  181.     APTR
  182.  
  183.     DESCRIPTION
  184.     we simply check if the command was a correct
  185.     menu-selection and return some data that was
  186.     stored together with the Intuition-structure
  187.  
  188.     NOTES
  189.     we don not know, the structure of that data;
  190.     so user might have to call macroname, macrobody
  191.     or something like that before he is getting the wanted data
  192.  
  193.     INTERNALS
  194.     falls korrekter Menueaufruf
  195.         gib entsprechendes Macro zurueck
  196.     sonst gib NULL zurueck
  197.  
  198. ******************************************************************************/
  199.  
  200. APTR menu_cmd (struct IntuiMessage * im)
  201. {
  202.     XITEM *item;
  203.  
  204.     if (item = (XITEM *)ItemAddress (((MENUSTRIP *)currentmenu())->data, im->Code)) {
  205.     return (item->com);
  206.     } /* if found item */
  207.     return (NULL);
  208. } /* menu_cmd */
  209.  
  210. #endif
  211.  
  212. /******************************************************************************
  213. *****  ENDE menucontrol.c
  214. ******************************************************************************/
  215.